using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Business.Dto;
using JTZY.Model.Business;
using JTZY.Service.Business.IBusinessService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-10-27
namespace JTZY.Admin.WebApi.Controllers.Business
{
    /// <summary>
    /// 业务员列表
    /// </summary>
    [Verify]
    [Route("business/SaleMan")]
    public class SaleManController : BaseController
    {
        /// <summary>
        /// 业务员列表接口
        /// </summary>
        private readonly ISaleManService _SaleManService;

        public SaleManController(ISaleManService SaleManService)
        {
            _SaleManService = SaleManService;
        }

        /// <summary>
        /// 查询业务员列表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "saleman:list")]
        public IActionResult QuerySaleMan([FromQuery] SaleManQueryDto parm)
        {
            parm.UserId = HttpContext.GetUId();
            var response = _SaleManService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询业务员列表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "saleman:query")]
        public IActionResult GetSaleMan(long Id)
        {
            var response = _SaleManService.GetInfo(Id);
            
            var info = response.Adapt<SaleManDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加业务员列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "saleman:add")]
        [Log(Title = "业务员列表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddSaleMan([FromBody] SaleManDto parm)
        {
            var modal = parm.Adapt<SaleMan>().ToCreate(HttpContext);
            modal.AgentId= HttpContext.GetUId();
            modal.OperDate = DateTime.Now;
            var response = _SaleManService.AddSaleMan(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新业务员列表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "saleman:edit")]
        [Log(Title = "业务员列表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateSaleMan([FromBody] SaleManDto parm)
        {
            var modal = parm.Adapt<SaleMan>().ToUpdate(HttpContext);
            var response = _SaleManService.UpdateSaleMan(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除业务员列表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "saleman:delete")]
        [Log(Title = "业务员列表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteSaleMan([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_SaleManService.Delete(idArr));
        }

    }
}